<?php

/**
 * This is the model class for table "zy_status".
 *
 * The followings are the available columns in table 'zy_status':
 * @property integer $status_id
 * @property integer $customer_id
 * @property integer $campaign_id
 * @property integer $agent_id
 * @property string $status
 * @property string $callback_date_and_time
 * @property string $last_called_date_and_time
 * @property string $notes
 * @property string $follow_up
 * @property string $sign_up_date
 * @property string $contract_expire_date
 * @property string $package
 */
class Status extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @param string $className active record class name.
	 * @return Status the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'zy_potential_status';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('customer_id,campaign_id, agent_id', 'numerical', 'integerOnly'=>true),
			array('status, callback_date_and_time, last_called_date_and_time, notes, follow_up, sign_up_date, contract_expire_date, package', 'length', 'max'=>255),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('status_id, customer_id,campaign_id, agent_id, status, callback_date_and_time, last_called_date_and_time, notes, follow_up, sign_up_date, contract_expire_date, package', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'status_id' => Yii::t('base','CallStatusID'),
			'customer_id' =>  Yii::t('base','Customer'),
			'campaign_id' =>  Yii::t('base','Campaign'),
			'agent_id' =>  Yii::t('base','Telesales People'),
			'status' =>  Yii::t('base','CallStatus'),
			'callback_date_and_time' =>  Yii::t('base','Callback Date And Time'),
			'last_called_date_and_time' => Yii::t('base', 'Last Called Date And Time'),
			'notes' => Yii::t('base','Note').':',
			'follow_up' =>  Yii::t('base','Follow Up'),
			'sign_up_date' =>  Yii::t('base','Sign Up Date'),
			'contract_expire_date' => Yii::t('base', 'Contract Expire Date'),
			'package' =>  Yii::t('base','Package'),
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;
		$criteria->compare('campaign_id',$this->campaign_id);
		$criteria->compare('status_id',$this->status_id);	
		$criteria->compare('customer_id',$this->customer_id);
		if($this->agent_id>0)
			$criteria->compare('agent_id',$this->agent_id);
		if($this->status>0)
			$criteria->compare('status',$this->status,true);
		$criteria->compare('callback_date_and_time',$this->callback_date_and_time,true);
		if($this->last_called_date_and_time!="")
			$criteria->compare('last_called_date_and_time',$this->last_called_date_and_time,true);
		/*$criteria->addSearchCondition('last_called_date_and_time',date("Y-m-d"));*/
		$criteria->compare('notes',$this->notes,true);
		$criteria->compare('follow_up',$this->follow_up,true);
		$criteria->compare('sign_up_date',$this->sign_up_date,true);
		$criteria->compare('contract_expire_date',$this->contract_expire_date,true);
		$criteria->compare('package',$this->package,true);

		return new CActiveDataProvider($this, array(
			'criteria'=>$criteria,
			'sort'=>array(
					'defaultOrder'=>'status desc',
				),
		));
	}
	//通过状态id得到状态的名字
	public function getStatusName($statusid)
	{
	if($statusid==1)
	{
	$statusname="No Answer";
	}elseif ($statusid==2)
	{
	$statusname="Busy or Not Available";	
	}elseif ($statusid==3)
	{
	$statusname="Invalid Number";
	}elseif ($statusid==4)
	{
	$statusname="Do not call again";
	}elseif ($statusid==5)
	{
	$statusname="No interest";
	}elseif ($statusid==6)
	{
	$statusname="Qualified lead";
	}elseif ($statusid==7)
	{
	$statusname="Won";
	}
	return $statusname;
	}
}